using System;

using Microsoft.SPOT;
using Microsoft.SPOT.Input;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Touch;
using Microsoft.SPOT.Hardware;
using Microsoft.SPOT.Net.NetworkInformation;

namespace eHouse
{
    class SettingsWindow:Window
    {
        Canvas canvas = new Canvas();
        private Window settingsWindow;

        NetworkInterface networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0];
        public SettingsWindow(Window mw)
        {
            settingsWindow = new Window();
            settingsWindow.Width = SystemMetrics.ScreenWidth;
            settingsWindow.Height = SystemMetrics.ScreenHeight;

            CreateWindow();
        }

        public void CreateWindow()
        {

            Text text_ip = new Text(Resources.GetFont(Resources.FontResources.NinaB), "");
            //text_ip.TextContent = "The IP address is: " + networkInterface.IPAddress.ToString();
            text_ip.TextContent = "The IP address is: " + Drivers.ip;
            Panel pan_text_ip = new Panel();
            pan_text_ip.Children.Add(text_ip);
            Canvas.SetTop(pan_text_ip, 50);
            Canvas.SetLeft(pan_text_ip, 0);
            canvas.Children.Add(pan_text_ip);

            Image image_edit_ip = new Image(Resources.GetBitmap(Resources.BitmapResources.edit));
            image_edit_ip.HorizontalAlignment = HorizontalAlignment.Center;
            image_edit_ip.VerticalAlignment = VerticalAlignment.Center;
            SimpleButton button_edit_ip = new SimpleButton(image_edit_ip, 45, 45);
            //Canvas.SetTop(button_edit_ip, 50);
            //Canvas.SetRight(button_edit_ip, 0);
            //canvas.Children.Add(button_edit_ip);

            Text text_date = new Text(Resources.GetFont(Resources.FontResources.NinaB),"");
            text_date.TextContent = "DATE: " + System.DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss");
            Panel pan_text_date = new Panel();
            pan_text_date.Children.Add(text_date);
            Canvas.SetTop(pan_text_date, 0);
            Canvas.SetLeft(pan_text_date, 0);
            canvas.Children.Add(pan_text_date);

            Image image_edit_date = new Image(Resources.GetBitmap(Resources.BitmapResources.edit));
            image_edit_date.HorizontalAlignment = HorizontalAlignment.Center;
            image_edit_date.VerticalAlignment = VerticalAlignment.Center;
            SimpleButton button_edit_date = new SimpleButton(image_edit_date, 45, 45);
            Canvas.SetTop(button_edit_date, 0);
            Canvas.SetRight(button_edit_date, 0);
            canvas.Children.Add(button_edit_date);

            Image image_return = new Image(Resources.GetBitmap(Resources.BitmapResources.imreturn));
            image_return.HorizontalAlignment = HorizontalAlignment.Center;
            image_return.VerticalAlignment = VerticalAlignment.Center;
            SimpleButton button_return = new SimpleButton(image_return, settingsWindow.Width / 2, settingsWindow.Height / 5);
            button_return.BackColor = Colors.White;
            Canvas.SetBottom(button_return, 0);
            Canvas.SetRight(button_return, 0);
            canvas.Children.Add(button_return);

            button_edit_ip.Click += new EventHandler(buttonEditIP_Click);
            button_edit_date.Click += new EventHandler(buttonEditDate_Click);
            button_return.Click += new EventHandler(buttonReturn_Click);

            settingsWindow.Child = canvas;
            settingsWindow.Visibility = Visibility.Visible;
        }

        void buttonEditIP_Click(object sender, EventArgs evt)
        {
            EditIPWindow eiw = new EditIPWindow(this);
        }

        void buttonEditDate_Click(object sender, EventArgs evt)
        {
            EditDateWindow edw = new EditDateWindow(this);
            settingsWindow.Close();
        }

        void buttonReturn_Click(object sender, EventArgs evt)
        {
            settingsWindow.Close();
        }
    }
}
